home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / info / gpc.i8 < prev    next >
Encoding:
GNU Info File  |  2001-02-09  |  88.3 KB  |  1,987 lines

  1. This is gpc.info, produced by makeinfo version 4.0 from gpc.texi.
  2.  
  3. INFO-DIR-SECTION GNU programming tools
  4. START-INFO-DIR-ENTRY
  5. * GPC: (gpc).                   The GNU Pascal Compiler.
  6. END-INFO-DIR-ENTRY
  7. INFO-DIR-SECTION Individual utilities
  8. START-INFO-DIR-ENTRY
  9. * GPC: (gpc)Invoking GPC.       The GNU Pascal Compiler.
  10. END-INFO-DIR-ENTRY
  11.  
  12.    This file documents the GNU Pascal Compiler.
  13.  
  14.    Copyright (C) 1988, 1996-2001 Free Software Foundation, Inc.
  15.  
  16.    Permission is granted to make and distribute verbatim copies of this
  17. manual provided the copyright notice and this permission notice are
  18. preserved on all copies.
  19.  
  20.    Permission is granted to copy and distribute modified versions of
  21. this manual under the conditions for verbatim copying, provided also
  22. that the sections entitled "GNU General Public License", "The GNU
  23. Project", "The GNU Manifesto" and "Funding for Free Software" are
  24. included exactly as in the original, and provided that the entire
  25. resulting derived work is distributed under the terms of a permission
  26. notice identical to this one.
  27.  
  28.    Permission is granted to copy and distribute translations of this
  29. manual into another language, under the above conditions for modified
  30. versions, except that the sections entitled "GNU General Public
  31. License", "The GNU Project", "The GNU Manifesto" and "Funding for Free
  32. Software" and this permission notice, may be included in translations
  33. approved by the Free Software Foundation instead of in the original
  34. English.
  35.  
  36. 
  37. File: gpc.info,  Node: Run Time System,  Next: GPC Units,  Prev: Notes for Debugging,  Up: Programming
  38.  
  39. Pascal declarations for GPC's Run Time System
  40. =============================================
  41.  
  42.    Below is a Pascal source of the declarations in GPC's Run Time
  43. System (RTS). A file `gpc.pas' with the same contents is included in
  44. the GPC distribution in a `units' subdirectory of the directory
  45. containing `libgcc.a'. (To find out the correct directory for your
  46. installation, type `gpc --print-file-name=units' on the command line.)
  47.  
  48.      {
  49.      Pascal declarations of the GPC Run Time System that are visible to
  50.      each program.
  51.      
  52.      This unit contains Pascal declarations of many RTS routines which
  53.      are not built into the compiler and can be called from programs.
  54.      Don't copy the declarations from this unit into your programs, but
  55.      rather include this unit with a `uses' statement. The reason is that
  56.      the internal declarations, e.g. the `asmnames', may change, and this
  57.      unit will be changed accordingly. @@In the future, this unit might
  58.      be included into every program automatically, so there will be no
  59.      need for a `uses' statement to make the declarations here available.
  60.      
  61.      Note about `protected var' parameters:
  62.      Since const parameters in GPC may be passed by value *or* by
  63.      reference internally, possibly depending on the system, `const foo*'
  64.      parameters to C functions *cannot* reliably declared as `const' in
  65.      Pascal. However, Extended Pascal's `protected var' can be used since
  66.      this guarantees passing by reference.
  67.      
  68.      Copyright (C) 1998-2001 Free Software Foundation, Inc.
  69.      
  70.      Author: Frank Heckenbach <frank@pascal.gnu.de>
  71.      
  72.      This file is part of GNU Pascal.
  73.      
  74.      GNU Pascal is free software; you can redistribute it and/or modify
  75.      it under the terms of the GNU General Public License as published by
  76.      the Free Software Foundation; either version 2, or (at your option)
  77.      any later version.
  78.      
  79.      GNU Pascal is distributed in the hope that it will be useful,
  80.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  81.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  82.      GNU General Public License for more details.
  83.      
  84.      You should have received a copy of the GNU General Public License
  85.      along with GNU Pascal; see the file COPYING. If not, write to the
  86.      Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  87.      02111-1307, USA.
  88.      
  89.      As a special exception, if you link this file with files compiled
  90.      with a GNU compiler to produce an executable, this does not cause
  91.      the resulting executable to be covered by the GNU General Public
  92.      License. This exception does not however invalidate any other
  93.      reasons why the executable file might be covered by the GNU General
  94.      Public License.
  95.      }
  96.      
  97.      {$gnu-pascal,B-,I-}
  98.      
  99.      module GPC interface;
  100.      
  101.      export
  102.        GPC = all;
  103.        GPC_SP = (eread (*@@not really, but an empty export doesn't
  104.        work*));
  105.        GPC_EP = (eread (*@@not really, but an empty export doesn't
  106.        work*));
  107.        GPC_BP = (MaxLongInt, ExitCode, ErrorAddr, Pos);
  108.        GPC_Delphi = (MaxLongInt, Int64, EConvertError, ExitCode,
  109.                      ErrorAddr, Pos, SetString, StringOfChar, TextFile,
  110.                      AssignFile, CloseFile);
  111.      
  112.      const
  113.        MaxLongInt = High (LongInt);
  114.      
  115.        { Maximum size of a variable }
  116.        MaxVarSize = MaxInt div 8;
  117.      
  118.      type
  119.        Int64 = Integer (64);
  120.      
  121.      { ====================== MEMORY MANAGEMENT ======================= }
  122.      
  123.      { Heap manipulation, from heap.c }
  124.      
  125.      { GPC implements both Mark/Release and Dispose. Both can be mixed
  126.        freely
  127.        in the same program. Dispose should be preferred, since it's
  128.        faster. }
  129.      
  130.      { C heap management routines. NOTE: if Release is used anywhere in
  131.        the program, CFreeMem and CReAllocMem may not be used for pointers
  132.        that were not allocated with CGetMem. }
  133.      function  CGetMem     (Size : SizeType) : Pointer; asmname 'malloc';
  134.      procedure CFreeMem    (aPointer : Pointer); asmname 'free';
  135.      function  CReAllocMem (aPointer : Pointer; NewSize : SizeType) :
  136.        Pointer; asmname 'realloc';
  137.      
  138.      type
  139.        GetMemType     = ^function (Size : SizeType) : Pointer;
  140.        FreeMemType    = ^procedure (aPointer : Pointer);
  141.        ReAllocMemType = ^function (aPointer : Pointer; NewSize :
  142.        SizeType) : Pointer;
  143.      
  144.      { These variables can be set to user-defined routines for memory
  145.        allocation/deallocation. GetMemPtr may return nil when
  146.        insufficient memory is available. GetMem/New will produce a
  147.        runtime error then. }
  148.      var
  149.        GetMemPtr     : GetMemType; asmname '_p_getmem_ptr'; external;
  150.        FreeMemPtr    : FreeMemType; asmname '_p_freemem_ptr'; external;
  151.        ReAllocMemPtr : ReAllocMemType; asmname '_p_reallocmem_ptr';
  152.        external;
  153.      
  154.        { Points to the lowest byte of heap used }
  155.        HeapBegin : Pointer; asmname '_p_heap_begin'; external;
  156.      
  157.        { Points to the highest byte of heap used }
  158.        HeapHigh  : Pointer; asmname '_p_heap_high'; external;
  159.      
  160.      const
  161.        UndocumentedReturnNil = Pointer (- 1);
  162.      
  163.      { Returns the number of pointers that would be released. aPointer
  164.        must
  165.        have been marked with Mark. For an example of its usage, see the
  166.        HeapMon unit. }
  167.      function  ReleaseCount (aPointer : Pointer) : Integer;
  168.        asmname '_p_releasecount';
  169.      
  170.      procedure ReAllocMem (var aPointer : Pointer; NewSize : SizeType);
  171.        asmname '_p_reallocmem';
  172.      
  173.      { Routines to handle endianness, from endian.pas }
  174.      
  175.      { Boolean constants about endianness and alignment }
  176.      
  177.      const
  178.        BitsBigEndian  = {$ifdef __BITS_LITTLE_ENDIAN__} False
  179.                         {$else}{$ifdef __BITS_BIG_ENDIAN__} True
  180.                         {$else}{$error Bit endianness is not defined!}
  181.                         {$endif}{$endif};
  182.      
  183.        BytesBigEndian = {$ifdef __BYTES_LITTLE_ENDIAN__} False
  184.                         {$else}{$ifdef __BYTES_BIG_ENDIAN__} True
  185.                         {$else}{$error Byte endianness is not defined!}
  186.                         {$endif}{$endif};
  187.      
  188.        WordsBigEndian = {$ifdef __WORDS_LITTLE_ENDIAN__} False
  189.                         {$else}{$ifdef __WORDS_BIG_ENDIAN__} True
  190.                         {$else}{$error Word endianness is not defined!}
  191.                         {$endif}{$endif};
  192.      
  193.        NeedAlignment  = {$ifdef __NEED_ALIGNMENT__} True
  194.                         {$else} False {$endif};
  195.      
  196.      { Convert single variables from or to little or big endian format.
  197.        This only works for a single variable or a plain array of a simple
  198.        type. For more complicated structures, this has to be done for
  199.        each component separately! Currently, ConvertFromFooEndian and
  200.        ConvertToFooEndian are the same, but this might not be the case on
  201.        middle-endian machines. Therefore, we provide different names. }
  202.      procedure ReverseBytes            (var Buf; ElementSize, Count :
  203.        SizeType); asmname '_p_reversebytes';
  204.      procedure ConvertFromLittleEndian (var Buf; ElementSize, Count :
  205.        SizeType); asmname '_p_convertlittleendian';
  206.      procedure ConvertFromBigEndian    (var Buf; ElementSize, Count :
  207.        SizeType); asmname '_p_convertbigendian';
  208.      procedure ConvertToLittleEndian   (var Buf; ElementSize, Count :
  209.        SizeType); asmname '_p_convertlittleendian';
  210.      procedure ConvertToBigEndian      (var Buf; ElementSize, Count :
  211.        SizeType); asmname '_p_convertbigendian';
  212.      
  213.      { Read a block from a file and convert it from little or
  214.        big endian format. This only works for a single variable or a
  215.        plain array of a simple type, note the comment for
  216.        `ConvertFromLittleEndian' and `ConvertFromBigEndian'. }
  217.      (*@@iocritical*)procedure BlockReadLittleEndian   (var aFile : File;
  218.        var   Buf; ElementSize, Count : SizeType);
  219.        asmname '_p_blockread_littleendian';
  220.      (*@@iocritical*)procedure BlockReadBigEndian      (var aFile : File;
  221.        var   Buf; ElementSize, Count : SizeType);
  222.        asmname '_p_blockread_bigendian';
  223.      
  224.      { Write a block variable to a file and convert it to little or big
  225.        endian format before. This only works for a single variable or a
  226.        plain array of a simple type. Apart from this, note the comment
  227.        for `ConvertToLittleEndian' and `ConvertToBigEndian'. }
  228.      (*@@iocritical*)procedure BlockWriteLittleEndian  (var aFile : File;
  229.        const Buf; ElementSize, Count : SizeType);
  230.        asmname '_p_blockwrite_littleendian';
  231.      (*@@iocritical*)procedure BlockWriteBigEndian     (var aFile : File;
  232.        const Buf; ElementSize, Count : SizeType);
  233.        asmname '_p_blockwrite_bigendian';
  234.      
  235.      { Read and write strings from/to binary files, where the length is
  236.        stored in the given endianness and with a fixed size (64 bits),
  237.        and therefore is independent of the system. }
  238.      (*@@iocritical*)procedure ReadStringLittleEndian  (var f : File; var
  239.        s : String); asmname '_p_ReadStringLittleEndian';
  240.      (*@@iocritical*)procedure ReadStringBigEndian     (var f : File; var
  241.        s : String); asmname '_p_ReadStringBigEndian';
  242.      (*@@iocritical*)procedure WriteStringLittleEndian (var f : File;
  243.        const s : String); asmname '_p_WriteStringLittleEndian';
  244.      (*@@iocritical*)procedure WriteStringBigEndian    (var f : File;
  245.        const s : String); asmname '_p_WriteStringBigEndian';
  246.      
  247.      { =================== STRING HANDLING ROUTINES =================== }
  248.      
  249.      { String handling routines, from string.pas }
  250.      
  251.      type
  252.        AnyFile = Text; (*@@ create `AnyFile' parameters*)
  253.        PAnyFile = ^AnyFile;
  254.      
  255.      { TString is a string type that is used for function results and
  256.        local variables, as long as undiscriminated strings are not
  257.        allowed there. The default size of 2048 characters should be
  258.        enough for file names on any system, but can be changed when
  259.        necessary. It should be at least as big as MAXPATHLEN. }
  260.      
  261.      const
  262.        TStringSize = 2048;
  263.        SpaceCharacters = [' ', #9];
  264.        NewLine = "\n"; { the separator of lines within a string }
  265.        LineBreak = {$ifdef __OS_DOS__} "\r\n" {$else} "\n" {$endif};
  266.        { the separator of lines within a file }
  267.      
  268.      type
  269.        TString    = String (TStringSize);
  270.        TStringBuf = packed array [0 .. TStringSize] of Char;
  271.        PString    = ^String;
  272.        CharSet    = set of Char;
  273.        PCStrings  = ^TCStrings;
  274.        TCStrings  = array [0 .. MaxVarSize div SizeOf (CString)] of
  275.        CString;
  276.      
  277.      var
  278.        CParamCount : Integer; asmname '_p_argc'; external;
  279.        CParameters : PCStrings; asmname '_p_argv'; external;
  280.      
  281.      function  MemCmp      (const s1, s2; Size : SizeType) : Integer;
  282.        asmname 'memcmp';
  283.      function  MemComp     (const s1, s2; Size : SizeType) : Integer;
  284.        asmname 'memcmp';
  285.      function  MemCompCase (const s1, s2; Size : SizeType) : Boolean;
  286.        asmname '_p_memcmpcase';
  287.      
  288.      procedure UpCaseString    (var s : String);
  289.        asmname '_p_upcase_string';
  290.      procedure LoCaseString    (var s : String);
  291.        asmname '_p_locase_string';
  292.      function  UpCaseStr       (const s : String) : TString;
  293.        asmname '_p_upcase_str';
  294.      function  LoCaseStr       (const s : String) : TString;
  295.        asmname '_p_locase_str';
  296.      
  297.      function  IsUpCase        (ch : Char) : Boolean;
  298.        attribute (const); asmname '_p_isupcase';
  299.      function  IsLoCase        (ch : Char) : Boolean;
  300.        attribute (const); asmname '_p_islocase';
  301.      function  IsAlpha         (ch : Char) : Boolean;
  302.        attribute (const); asmname '_p_isalpha';
  303.      function  IsAlphaNum      (ch : Char) : Boolean;
  304.        attribute (const); asmname '_p_isalphanum';
  305.      function  IsAlphaNumUnderscore (ch : Char) : Boolean;
  306.        attribute (const); asmname '_p_isalphanumunderscore';
  307.      function  IsSpace         (ch : Char) : Boolean;
  308.        attribute (const); asmname '_p_isspace';
  309.      function  IsPrintable     (ch : Char) : Boolean;
  310.        attribute (const); asmname '_p_isprintable';
  311.      
  312.      function  StrEqualCase    (const s1, s2 : String) : Boolean;
  313.        asmname '_p_strequalcase';
  314.      
  315.      function  Pos             (const SubString, aString : String) :
  316.        Integer; asmname '_p_pos';
  317.      function  LastPos         (const SubString, aString : String) :
  318.        Integer; asmname '_p_lastpos';
  319.      function  PosCase         (const SubString, aString : String) :
  320.        Integer; asmname '_p_poscase';
  321.      function  LastPosCase     (const SubString, aString : String) :
  322.        Integer; asmname '_p_lastposcase';
  323.      function  CharPos         (const Chars : CharSet; const aString :
  324.        String) : Integer; asmname '_p_charpos';
  325.      function  LastCharPos     (const Chars : CharSet; const aString :
  326.        String) : Integer; asmname '_p_lastcharpos';
  327.      
  328.      function  PosFrom         (const SubString, aString : String; From :
  329.        Integer) : Integer; asmname '_p_posfrom';
  330.      function  LastPosTill     (const SubString, aString : String; Till :
  331.        Integer) : Integer; asmname '_p_lastpostill';
  332.      function  PosFromCase     (const SubString, aString : String; From :
  333.        Integer) : Integer; asmname '_p_posfromcase';
  334.      function  LastPosTillCase (const SubString, aString : String; Till :
  335.        Integer) : Integer; asmname '_p_lastpostillcase';
  336.      function  CharPosFrom     (const Chars : CharSet; const aString :
  337.        String; From : Integer) : Integer; asmname '_p_charposfrom';
  338.      function  LastCharPosTill (const Chars : CharSet; const aString :
  339.        String; Till : Integer) : Integer; asmname '_p_lastcharpostill';
  340.      
  341.      function  IsPrefix        (const Prefix, s : String) : Boolean;
  342.        asmname '_p_isprefix';
  343.      function  IsSuffix        (const Suffix, s : String) : Boolean;
  344.        asmname '_p_issuffix';
  345.      function  IsPrefixCase    (const Prefix, s : String) : Boolean;
  346.        asmname '_p_isprefixcase';
  347.      function  IsSuffixCase    (const Suffix, s : String) : Boolean;
  348.        asmname '_p_issuffixcase';
  349.      
  350.      function  CStringLength      (Src : CString) : SizeType;
  351.        asmname '_p_strlen';
  352.      function  CStringEnd         (Src : CString) : CString;
  353.        asmname '_p_strend';
  354.      function  CStringNew         (Src : CString) : CString;
  355.        asmname '_p_strdup';
  356.      function  CStringComp        (s1, s2 : CString) : Integer;
  357.        asmname '_p_strcmp';
  358.      function  CStringCaseComp    (s1, s2 : CString) : Integer;
  359.        asmname '_p_strcasecmp';
  360.      function  CStringLComp       (s1, s2 : CString; MaxLen : SizeType) :
  361.        Integer; asmname '_p_strlcmp';
  362.      function  CStringLCaseComp   (s1, s2 : CString; MaxLen : SizeType) :
  363.        Integer; asmname '_p_strlcasecmp';
  364.      function  CStringCopy        (Dest, Source : CString) : CString;
  365.        asmname '_p_strcpy';
  366.      function  CStringCopyEnd     (Dest, Source : CString) : CString;
  367.        asmname '_p_strecpy';
  368.      function  CStringLCopy       (Dest, Source : CString; MaxLen :
  369.        SizeType) : CString; asmname '_p_strlcpy';
  370.      function  CStringMove        (Dest, Source : CString; Count :
  371.        SizeType) : CString; asmname '_p_strmove';
  372.      function  CStringCat         (Dest, Source : CString) : CString;
  373.        asmname '_p_strcat';
  374.      function  CStringLCat        (Dest, Source : CString; MaxLen :
  375.        SizeType) : CString; asmname '_p_strlcat';
  376.      function  CStringChPos       (Src : CString; Ch : Char) : CString;
  377.        asmname '_p_strscan';
  378.      function  CStringLastChPos   (Src : CString; Ch : Char) : CString;
  379.        asmname '_p_strrscan';
  380.      function  CStringPos         (aString, SubString : CString) :
  381.        CString; asmname '_p_strpos';
  382.      function  CStringLastPos     (aString, SubString : CString) :
  383.        CString; asmname '_p_strrpos';
  384.      function  CStringCasePos     (aString, SubString : CString) :
  385.        CString; asmname '_p_strcasepos';
  386.      function  CStringLastCasePos (aString, SubString : CString) :
  387.        CString; asmname '_p_strrcasepos';
  388.      function  CStringUpCase      (s : CString) : CString;
  389.        asmname '_p_strupper';
  390.      function  CStringLoCase      (s : CString) : CString;
  391.        asmname '_p_strlower';
  392.      function  CStringIsEmpty     (s : CString) : Boolean;
  393.        asmname '_p_strempty';
  394.      function  NewCString         (const Source : String) : CString;
  395.        asmname '_p_newcstring';
  396.      function  CStringCopyString  (Dest : CString; const Source :
  397.        String) : CString; asmname '_p_cstringcopystring';
  398.      procedure CopyCString        (Source : CString; var Dest : String);
  399.        asmname '_p_copycstring';
  400.      
  401.      function  NewString       (const s : String) : PString;
  402.        asmname '_p_newstring';
  403.      procedure DisposeString   (p : PString); asmname '_p_dispose';
  404.      
  405.      procedure SetString       (var s : String; Buffer : PChar; Count :
  406.        Integer); asmname '_p_set_string';
  407.      function  StringOfChar    (Ch : Char; Count : Integer) = s :
  408.        TString; asmname '_p_string_of_char';
  409.      
  410.      procedure TrimLeft        (var s : String); asmname '_p_trimleft';
  411.      procedure TrimRight       (var s : String); asmname '_p_trimright';
  412.      procedure TrimBoth        (var s : String); asmname '_p_trimboth';
  413.      function  TrimLeftStr     (const s : String) : TString;
  414.        asmname '_p_trimleft_str';
  415.      function  TrimRightStr    (const s : String) : TString;
  416.        asmname '_p_trimright_str';
  417.      function  TrimBothStr     (const s : String) : TString;
  418.        asmname '_p_trimboth_str';
  419.      
  420.      function  GetStringCapacity (const s : String) : Integer;
  421.        asmname '_p_get_string_capacity';
  422.      
  423.      { A shortcut for a common use of WriteStr as a function }
  424.      function  Integer2String (i : Integer) : TString;
  425.        asmname '_p_Integer2String';
  426.      
  427.      type
  428.        TChars = packed array [1 .. 1] of Char;
  429.        PChars = ^TChars;
  430.      
  431.        { Under development. Interface subject to change.
  432.          Use with caution. }
  433.        { When a const or var AnyString parameter is passed, internally
  434.          these records are passed as const parameters. Value AnyString
  435.          parameters are passed like value string parameters. }
  436.        ConstAnyString = record
  437.          Length : Integer;
  438.          Chars  : PChars
  439.        end;
  440.      
  441.        { Capacity is the allocated space (used internally). Count is the
  442.          actual number of environment strings. The CStrings array
  443.          contains the environment strings, terminated by a nil pointer,
  444.          which is not counted in Count. @CStrings can be passed to libc
  445.          routines like execve which expect an environment (see
  446.          GetCEnvironment). }
  447.        PEnvironment = ^TEnvironment;
  448.        TEnvironment (Capacity : Integer) = record
  449.          Count : Integer;
  450.          CStrings : array [1 .. Capacity + 1] of CString
  451.        end;
  452.      
  453.      var
  454.        Environment : PEnvironment; asmname '_p_environment'; external;
  455.      
  456.      { Get an environment variable. If it does not exist, GetEnv returns
  457.        the empty string, which can't be distinguished from a variable
  458.        with an empty value, while CStringGetEnv returns nil then. Note,
  459.        Dos doesn't know empty environment variables, but treats them as
  460.        non-existing, and does not distinguish case in the names of
  461.        environment variables. However, even under Dos, empty environment
  462.        variables and variable names with different case can now be set
  463.        and used within GPC programs. }
  464.      function  GetEnv (const EnvVar : String) : TString;
  465.        asmname '_p_getenv';
  466.      function  CStringGetEnv (EnvVar : CString) : CString;
  467.        asmname '_p_cstringgetenv';
  468.      
  469.      { Sets an environment variable with the name given in VarName to the
  470.        value
  471.        Value. A previous value, if any, is overwritten. }
  472.      procedure SetEnv (const VarName, Value : String);
  473.        asmname '_p_setenv';
  474.      
  475.      { Un-sets an environment variable with the name given in VarName. }
  476.      procedure UnSetEnv (const VarName : String); asmname '_p_unsetenv';
  477.      
  478.      { Returns @Environment^.CStrings, converted to PCStrings, to be
  479.        passed to
  480.        libc routines like execve which expect an environment. }
  481.      function  GetCEnvironment : PCStrings; asmname '_p_getcenvironment';
  482.      
  483.      { ================= RUNTIME ERROR HANDLING ETC. ================== }
  484.      
  485.      { Error handling functions, from error.pas }
  486.      
  487.      const
  488.        EOpen = 405;
  489.        EOpenRead = 442;
  490.        EOpenWrite = 443;
  491.        EOpenUpdate = 444;
  492.        EReading = 464;
  493.        EWriting = 466;
  494.        ERead = 413;
  495.        EWrite = 414;
  496.        EWriteReadOnly = 422;
  497.        EMMap = 408;
  498.        EIOCtl = 630;
  499.        EConvertError = 875;
  500.      
  501.      var
  502.        { Error number (after runtime error) or exit status (after Halt)
  503.        or
  504.          0 (during program run and after succesful termination). }
  505.        ExitCode : Integer; asmname '_p_exitcode'; external;
  506.      
  507.        { Contains the address of the code where a runtime occurred, nil
  508.          if no runtime error occurred. }
  509.        ErrorAddr : Pointer; asmname '_p_erroraddr'; external;
  510.      
  511.        { Error message }
  512.        ErrorMessageString : TString; asmname '_p_errormessagestring';
  513.        external;
  514.      
  515.      function  GetErrorMessage                 (n : Integer) : CString;
  516.        asmname '_p_errmsg';
  517.      procedure RuntimeError                    (n : Integer);
  518.        attribute (noreturn); asmname '_p_error';
  519.      procedure RuntimeErrorInteger             (n : Integer; i : MedInt);
  520.        attribute (noreturn); asmname '_p_error_integer';
  521.      procedure RuntimeErrorCString             (n : Integer; s :
  522.        CString);                attribute (noreturn);
  523.        asmname '_p_error_string';
  524.      procedure InternalError                   (n : Integer);
  525.        attribute (noreturn); asmname '_p_internal_error';
  526.      procedure InternalErrorInteger            (n : Integer; i : MedInt);
  527.        attribute (noreturn); asmname '_p_internal_error_integer';
  528.      procedure RuntimeWarning                  (Message : CString);
  529.        asmname '_p_warning';
  530.      procedure RuntimeWarningInteger           (Message : CString; i :
  531.        MedInt); asmname '_p_warning_integer';
  532.      procedure RuntimeWarningCString           (Message : CString; s :
  533.        CString); asmname '_p_warning_string';
  534.      procedure DebugStatement                  (const FileName : String;
  535.        Line : Integer); asmname '_p_debug_statement';
  536.      
  537.      (*iocritical*)procedure IOError                         (n :
  538.        Integer); asmname '_p_io_error';
  539.      (*iocritical*)procedure IOErrorInteger                  (n :
  540.        Integer; i : MedInt); asmname '_p_io_error_integer';
  541.      (*iocritical*)procedure IOErrorCString                  (n :
  542.        Integer; s : CString); asmname '_p_io_error_string';
  543.      (*iocritical*)procedure IOErrorFile                     (n :
  544.        Integer; protected var f : AnyFile); asmname '_p_io_error_file';
  545.      function  GetIOErrorMessage : TString;
  546.        asmname '_p_get_io_error_message';
  547.      procedure CheckInOutRes; asmname '_p_check_inoutres';
  548.      
  549.      { Registers a procedure to be called to restore the terminal for
  550.        another process that accesses the terminal, or back for the
  551.        program itself. Used e.g. by the CRT unit. The procedures must
  552.        allow for being called multiple times in any order, even at the
  553.        end of the program (see the comment for RestoreTerminal). }
  554.      procedure RegisterRestoreTerminal (ForAnotherProcess : Boolean;
  555.        procedure Proc); asmname '_p_RegisterRestoreTerminal';
  556.      
  557.      { Unregisters a procedure registered with RegisterRestoreTerminal.
  558.        Returns False if the procedure had not been registered, and True
  559.        if it had been registered and was unregistered successfully. }
  560.      function UnregisterRestoreTerminal (ForAnotherProcess : Boolean;
  561.        procedure Proc) : Boolean; asmname '_p_UnregisterRestoreTerminal';
  562.      
  563.      { Calls the procedures registered by RegisterRestoreTerminal. When
  564.        restoring the terminal for another process, the procedures are
  565.        called in the opposite order of registration. When restoring back
  566.        for the program, they are called in the order of registration.
  567.      
  568.        `RestoreTerminal (True)' will also be called at the end of the
  569.        program, before outputting any runtime error message. It can also
  570.        be used if you want to write an error message and exit the program
  571.        (especially when using e.g. the CRT unit). For this purpose, to
  572.        avoid side effects, call RestoreTerminal immediately before
  573.        writing the error message (to StdErr, not to Output!), and then
  574.        exit the program (e.g. with Halt). }
  575.      procedure RestoreTerminal (ForAnotherProcess : Boolean);
  576.        asmname '_p_RestoreTerminal';
  577.      
  578.      { Executes a command line. Reports execution errors via the IOResult
  579.        mechanism and returns the exit status of the executed program.
  580.        Execute calls RestoreTerminal with the argument True before and
  581.        False after executing the process, ExecuteNoTerminal does not. }
  582.      (*@@IO critical*)function  Execute (const CmdLine : String) :
  583.        Integer; asmname '_p_execute';
  584.      (*@@IO critical*)function  ExecuteNoTerminal (const CmdLine :
  585.        String) : Integer; asmname '_p_executenoterminal';
  586.      
  587.      procedure AtExit (procedure Proc); asmname '_p_atexit';
  588.      
  589.      procedure SetReturnAddress (Address : Pointer);
  590.        asmname '_p_SetReturnAddress';
  591.      procedure RestoreReturnAddress; asmname '_p_RestoreReturnAddress';
  592.      
  593.      { ==================== SIGNALS AND PROCESSES ===================== }
  594.      
  595.      function  ProcessID : Integer; asmname '_p_pid';
  596.      
  597.      { Extract information from the status returned by PWait }
  598.      function StatusExited     (Status : Integer) : Boolean; attribute
  599.        (const); asmname '_p_WIfExited';
  600.      function StatusExitCode   (Status : Integer) : Integer; attribute
  601.        (const); asmname '_p_WExitStatus';
  602.      function StatusSignaled   (Status : Integer) : Boolean; attribute
  603.        (const); asmname '_p_WIfSignaled';
  604.      function StatusTermSignal (Status : Integer) : Integer; attribute
  605.        (const); asmname '_p_WTermSig';
  606.      function StatusStopped    (Status : Integer) : Boolean; attribute
  607.        (const); asmname '_p_WIfStopped';
  608.      function StatusStopSignal (Status : Integer) : Integer; attribute
  609.        (const); asmname '_p_WStopSig';
  610.      
  611.      type
  612.        TSignalHandler = procedure (Signal : Integer);
  613.      
  614.      { OldHandler and OldRestart may be null }
  615.      function InstallSignalHandler (Signal : Integer; Handler :
  616.        TSignalHandler;
  617.                                     Restart, UnlessIgnored : Boolean;
  618.                                     var OldHandler : TSignalHandler; var
  619.        OldRestart : Boolean) : Boolean; asmname '_p_sigaction';
  620.      procedure BlockSignal   (Signal : Integer; Block : Boolean);
  621.        asmname '_p_BlockSignal';
  622.      function  SignalBlocked (Signal : Integer) : Boolean;
  623.        asmname '_p_SignalBlocked';
  624.      
  625.      var
  626.        { Signal actions }
  627.        SignalDefault : TSignalHandler; asmname '_p_SIG_DFL'; external;
  628.        SignalIgnore  : TSignalHandler; asmname '_p_SIG_IGN'; external;
  629.        SignalError   : TSignalHandler; asmname '_p_SIG_ERR'; external;
  630.      
  631.        { Signals. The constants are set to the signal numbers, and
  632.          are 0 for signals not defined. }
  633.        { POSIX signals }
  634.        SigHUp    : Integer; asmname '_p_SIGHUP'; external;
  635.        SigInt    : Integer; asmname '_p_SIGINT'; external;
  636.        SigQuit   : Integer; asmname '_p_SIGQUIT'; external;
  637.        SigIll    : Integer; asmname '_p_SIGILL'; external;
  638.        SigAbrt   : Integer; asmname '_p_SIGABRT'; external;
  639.        SigFPE    : Integer; asmname '_p_SIGFPE'; external;
  640.        SigKill   : Integer; asmname '_p_SIGKILL'; external;
  641.        SigSegV   : Integer; asmname '_p_SIGSEGV'; external;
  642.        SigPipe   : Integer; asmname '_p_SIGPIPE'; external;
  643.        SigAlrm   : Integer; asmname '_p_SIGALRM'; external;
  644.        SigTerm   : Integer; asmname '_p_SIGTERM'; external;
  645.        SigUsr1   : Integer; asmname '_p_SIGUSR1'; external;
  646.        SigUsr2   : Integer; asmname '_p_SIGUSR2'; external;
  647.        SigChld   : Integer; asmname '_p_SIGCHLD'; external;
  648.        SigCont   : Integer; asmname '_p_SIGCONT'; external;
  649.        SigStop   : Integer; asmname '_p_SIGSTOP'; external;
  650.        SigTStp   : Integer; asmname '_p_SIGTSTP'; external;
  651.        SigTTIn   : Integer; asmname '_p_SIGTTIN'; external;
  652.        SigTTOu   : Integer; asmname '_p_SIGTTOU'; external;
  653.      
  654.        { Non-POSIX signals }
  655.        SigTrap   : Integer; asmname '_p_SIGTRAP'; external;
  656.        SigIOT    : Integer; asmname '_p_SIGIOT'; external;
  657.        SigEMT    : Integer; asmname '_p_SIGEMT'; external;
  658.        SigBus    : Integer; asmname '_p_SIGBUS'; external;
  659.        SigSys    : Integer; asmname '_p_SIGSYS'; external;
  660.        SigStkFlt : Integer; asmname '_p_SIGSTKFLT'; external;
  661.        SigUrg    : Integer; asmname '_p_SIGURG'; external;
  662.        SigIO     : Integer; asmname '_p_SIGIO'; external;
  663.        SigPoll   : Integer; asmname '_p_SIGPOLL'; external;
  664.        SigXCPU   : Integer; asmname '_p_SIGXCPU'; external;
  665.        SigXFSz   : Integer; asmname '_p_SIGXFSZ'; external;
  666.        SigVTAlrm : Integer; asmname '_p_SIGVTALRM'; external;
  667.        SigProf   : Integer; asmname '_p_SIGPROF'; external;
  668.        SigPwr    : Integer; asmname '_p_SIGPWR'; external;
  669.        SigInfo   : Integer; asmname '_p_SIGINFO'; external;
  670.        SigLost   : Integer; asmname '_p_SIGLOST'; external;
  671.        SigWinCh  : Integer; asmname '_p_SIGWINCH'; external;
  672.      
  673.        { Signal subcodes (only used on some systems, -1 if not used) }
  674.        FPEIntegerOverflow        : Integer; asmname '_p_FPE_INTOVF_TRAP';
  675.        external;
  676.        FPEIntegerDivisionByZero  : Integer; asmname '_p_FPE_INTDIV_TRAP';
  677.        external;
  678.        FPESubscriptRange         : Integer; asmname '_p_FPE_SUBRNG_TRAP';
  679.        external;
  680.        FPERealOverflow           : Integer; asmname '_p_FPE_FLTOVF_TRAP';
  681.        external;
  682.        FPERealDivisionByZero     : Integer; asmname '_p_FPE_FLTDIV_TRAP';
  683.        external;
  684.        FPERealUnderflow          : Integer; asmname '_p_FPE_FLTUND_TRAP';
  685.        external;
  686.        FPEDecimalOverflow        : Integer; asmname '_p_FPE_DECOVF_TRAP';
  687.        external;
  688.      
  689.      { Returns a description for a signal }
  690.      function  StrSignal (Signal : Integer) : TString;
  691.        asmname '_p_strsignal';
  692.      
  693.      { Sends a signal to a process. Returns True if successful. If Signal
  694.        is 0, it doesn't send a signal, but still checks whether it would
  695.        be possible to send a signal to the given process. }
  696.      function  Kill (PID, Signal : Integer) : Boolean; asmname '_p_kill';
  697.      
  698.      const
  699.        AnyChild = - 1;
  700.      
  701.      { Waits for a child process with the given PID (or any child process
  702.        if PID = AnyChild) to terminate or be stopped. Returns the PID of
  703.        the process. WStatus will contain the status and can be evaluated
  704.        with StatusExited etc.. If nothing happened, and Block is False,
  705.        the function will return 0, and WStatus will be 0. If an error
  706.        occurred (especially on single tasking systems where WaitPID is
  707.        not possible), the function will return a negative value, and
  708.        WStatus will be 0. }
  709.      function  WaitPID (PID : Integer; var WStatus : Integer; Block :
  710.        Boolean) : Integer; asmname '_p_waitpid';
  711.      
  712.      { Sets the process group of Process (or the current one if Process
  713.        is 0) to ProcessGroup (or its PID if ProcessGroup is 0). Returns
  714.        True if successful. }
  715.      function  SetProcessGroup (Process, ProcessGroup : Integer) :
  716.        Boolean; asmname '_p_setpgid';
  717.      
  718.      { Sets the process group of a terminal given by Terminal (as a file
  719.        handle) to ProcessGroup. ProcessGroup must be the ID of a process
  720.        group in the same session. Returns True if successful. }
  721.      function  SetTerminalProcessGroup (Terminal, ProcessGroup :
  722.        Integer) : Boolean; asmname '_p_tcsetpgrp';
  723.      
  724.      { Returns the process group of a terminal given by Terminal (as a
  725.        file handle), or -1 on error. }
  726.      function  GetTerminalProcessGroup (Terminal : Integer) : Integer;
  727.        asmname '_p_tcgetpgrp';
  728.      
  729.      { Returns the file name of the terminal device that is open on the
  730.        file f. Returns nil if (and only if) f is not open or not
  731.        connected to a terminal. }
  732.      function  GetTerminalName (protected var f : AnyFile) : CString;
  733.        asmname '_p_ttyname';
  734.      
  735.      { Set the standard input's signal generation, if it is a terminal. }
  736.      procedure SetInputSignals (Signals : Boolean);
  737.        asmname '_p_set_isig';
  738.      
  739.      { Get the standard input's signal generation, if it is a terminal. }
  740.      function  GetInputSignals : Boolean; asmname '_p_get_isig';
  741.      
  742.      { Returns the real or effective user ID of the process. }
  743.      function  UserID  (Effective : Boolean) : Integer; asmname '_p_uid';
  744.      
  745.      { Returns the real or effective group ID of the process. }
  746.      function  GroupID (Effective : Boolean) : Integer; asmname '_p_gid';
  747.      
  748.      { ================= COMMAND LINE OPTION PARSING ================== }
  749.      
  750.      const
  751.        EndOfOptions      = #255;
  752.        NoOption          = #1;
  753.        UnknownOption     = '?';
  754.        LongOption        = #0;
  755.        UnknownLongOption = '?';
  756.      
  757.      var
  758.        FirstNonOption         : Integer; asmname '_p_first_non_option';
  759.        external;
  760.        HasOptionArgument      : Boolean;
  761.        asmname '_p_has_option_argument';      external;
  762.        OptionArgument         : TString; asmname '_p_option_argument';
  763.        external;
  764.        UnknownOptionCharacter : Char;
  765.        asmname '_p_unknown_option_character'; external;
  766.        GetOptErrorFlag        : Boolean; asmname '_p_getopt_error_flag';
  767.        external;
  768.      
  769.      {
  770.        Parses command line arguments for options and returns the next
  771.        one.
  772.      
  773.        If a command line argument starts with `-', and is not exactly `-'
  774.        or `--', then it is an option element. The characters of this
  775.        element (aside from the initial `-') are option characters. If
  776.        `GetOpt' is called repeatedly, it returns successively each of the
  777.        option characters from each of the option elements.
  778.      
  779.        If `GetOpt' finds another option character, it returns that
  780.        character, updating `FirstNonOption' and internal variables so
  781.        that the next call to `GetOpt' can resume the scan with the
  782.        following option character or command line argument.
  783.      
  784.        If there are no more option characters, `GetOpt' returns
  785.        EndOfOptions. Then `FirstNonOption' is the index of the first
  786.        command line argument that is not an option. (The command line
  787.        arguments have been permuted so that those that are not options
  788.        now come last.)
  789.      
  790.        OptString must be of the form `[+|-]abcd:e:f:g::h::i::'.
  791.      
  792.        a, b, c are options without arguments
  793.        d, e, f are options with required arguments
  794.        g, h, i are options with optional arguments
  795.      
  796.        Arguments are text following the option character in the same
  797.        command line argument, or the text of the following command line
  798.        argument. They are returned in OptionArgument. If an option has no
  799.        argument, OptionArgument is empty. The variable HasOptionArgument
  800.        tells whether an option has an argument. This is mostly useful for
  801.        options with optional arguments, if one wants to distinguish an
  802.        empty argument from no argument.
  803.      
  804.        If the first character of OptString is `+', GetOpt stops at the
  805.        first non-option argument.
  806.      
  807.        If it is `-', GetOpt treats non-option arguments as options and
  808.        return NoOption for them.
  809.      
  810.        Otherwise, GetOpt permutes arguments and handles all options,
  811.        leaving all non-options at the end. However, if the environment
  812.        variable POSIXLY_CORRECT is set, the default behaviour is to stop
  813.        at the first non-option argument, as with `+'.
  814.      
  815.        The special argument `--' forces an end of option-scanning
  816.        regardless of the first character of OptString. In the case of
  817.        `-', only `--' can cause GetOpt to return EndOfOptions with
  818.        FirstNonOption <= ParamCount.
  819.      
  820.        If an option character is seen that is not listed in OptString,
  821.        UnknownOption is returned. The unrecognized option character is
  822.        stored in UnknownOptionCharacter. Unless GetOptErrorFlag is set to
  823.        False, an error message is printed to StdErr automatically.
  824.      }
  825.      function GetOpt (const OptString : String) : Char;
  826.        asmname '_p_getopt';
  827.      
  828.      type
  829.        OptArgType = (NoArgument, RequiredArgument, OptionalArgument);
  830.      
  831.        OptionType = record
  832.          Name     : CString;
  833.          Argument : OptArgType;
  834.          Flag     : ^Char; { if nil, V is returned. Otherwise, Flag^ is }
  835.          V        : Char   { set to V, and LongOption is returned }
  836.        end;
  837.      
  838.      {
  839.        Recognize short options, described by OptString as above, and long
  840.        options, described by LongOptions.
  841.      
  842.        Long-named options begin with `--' instead of `-'. Their names may
  843.        be abbreviated as long as the abbreviation is unique or is an
  844.        exact match for some defined option. If they have an argument, it
  845.        follows the option name in the same argument, separated from the
  846.        option name by a `=', or else the in next argument. When GetOpt
  847.        finds a long-named option, it returns LongOption if that option's
  848.        `Flag' field is non-nil, and the value of the option's `V' field
  849.        if the `Flag' field is nil.
  850.      
  851.        LongIndex, if not null, returns the index in LongOptions of the
  852.        long-named option found. It is only valid when a long-named option
  853.        has been found by the most recent call.
  854.      
  855.        If LongOnly is set, `-' as well as `--' can indicate a long
  856.        option. If an option that starts with `-' (not `--') doesn't match
  857.        a long option, but does match a short option, it is parsed as a
  858.        short option instead. If an argument has the form `-f', where f is
  859.        a valid short option, don't consider it an abbreviated form of a
  860.        long option that starts with `f'. Otherwise there would be no way
  861.        to give the `-f' short option. On the other hand, if there's a
  862.        long option `fubar' and the argument is `-fu', do consider that an
  863.        abbreviation of the long option, just like `--fu', and not `-f'
  864.        with argument `u'. This distinction seems to be the most useful
  865.        approach.
  866.      
  867.        As an additional feature (not present in the C counterpart), if
  868.        the last character of OptString is `-' (after a possible starting
  869.        `+' or `-' character), or OptString is empty, all long options
  870.        with a nil `Flag' field will automatically be recognized as short
  871.        options with the character given by the `V' field. This means, in
  872.        the common (and recommended) case that all short options have long
  873.        equivalents, you can simply pass an empty OptString (or pass `+-'
  874.        or `--' as OptString if you want this behaviour, see the comment
  875.        for GetOpt), and you will only have to maintain the LongOptions
  876.        array when you add or change options.
  877.      }
  878.      function GetOptLong (const OptString : String; var LongOptions :
  879.        array [m .. n : Integer] of OptionType { can be null };
  880.                           var LongIndex : Integer { can be null };
  881.        LongOnly : Boolean) : Char; asmname '_p_getopt_long';
  882.      
  883.      { Reset GetOpt's state and make the next GetOpt or GetOptLong start
  884.        (again) with the StartArgument'th argument (may be 1). This is
  885.        useful for special purposes only. It is *necessary* to do this
  886.        after altering the contents of CParamCount/CParameters (which is
  887.        not usually done, either). }
  888.      procedure ResetGetOpt (StartArgument : Integer);
  889.        asmname '_p_ResetGetOpt';
  890.      
  891.      { =========================== PEXECUTE =========================== }
  892.      
  893.      const
  894.        PExecute_First   = 1;
  895.        PExecute_Last    = 2;
  896.        PExecute_One     = PExecute_First or PExecute_Last;
  897.        PExecute_Search  = 4;
  898.        PExecute_Verbose = 8;
  899.      
  900.      {
  901.        PExecute: execute a program.
  902.      
  903.        Program and Arguments are the arguments to execv/execvp.
  904.      
  905.        Flags and PExecute_Search is non-zero if $PATH should be searched
  906.        (It's not clear that GCC passes this flag correctly). Flags and
  907.        PExecute_First is nonzero for the first process in chain. Flags
  908.        and PExecute_Last is nonzero for the last process in chain.
  909.      
  910.        The result is the pid on systems like Unix where we fork/exec and
  911.        on systems like MS-Windows and OS2 where we use spawn. It is up to
  912.        the caller to wait for the child.
  913.      
  914.        The result is the exit code on systems like MSDOS where we spawn
  915.        and wait for the child here.
  916.      
  917.        Upon failure, ErrMsg is set to the text of the error message,
  918.        and -1 is returned. `errno' is available to the caller to use.
  919.      
  920.        PWait: cover function for wait.
  921.      
  922.        PID is the process id of the task to wait for. Status is the
  923.        `status' argument to wait. Flags is currently unused (allows
  924.        future enhancement without breaking upward compatibility). Pass 0
  925.        for now.
  926.      
  927.        The result is the process ID of the child reaped, or -1 for
  928.        failure.
  929.      
  930.        On systems that don't support waiting for a particular child, PID
  931.        is ignored. On systems like MSDOS that don't really multitask
  932.        PWait is just a mechanism to provide a consistent interface for
  933.        the caller.
  934.      }
  935.      function PExecute (ProgramName : CString; Arguments : PCStrings; var
  936.        ErrMsg : String; Flags : Integer) : Integer;
  937.        asmname '_p_pexecute';
  938.      function PWait (PID : Integer; var Status : Integer; Flags :
  939.        Integer) : Integer; asmname 'pwait';
  940.      
  941.      { ==================== TIME HANDLING ROUTINES ==================== }
  942.      
  943.      { Time and date routines for Extended Pascal, from time.pas }
  944.      
  945.      const
  946.        DateLength = 11; { from types.h }
  947.        TimeLength = 8;  { from types.h }
  948.        InvalidYear = - MaxInt;
  949.      
  950.      type
  951.        UnixTimeType = LongInt; { This is hard-coded in the compiler. Do
  952.        not change here. }
  953.        MicroSecondTimeType = LongInt;
  954.      
  955.        DateString = packed array [1 .. DateLength] of Char;
  956.        TimeString = packed array [1 .. TimeLength] of Char;
  957.      
  958.      var
  959.        { DayOfWeekName is a constant and therefore does not respect the
  960.          locale. Therefore, it's recommended to use FormatTime instead. }
  961.        DayOfWeekName : array [0 .. 6] of String [9];
  962.        asmname '_p_downame'; external;
  963.      
  964.        { MonthName is a constant and therefore does not respect the
  965.          locale. Therefore, it's recommended to use FormatTime instead. }
  966.        MonthName : array [1 .. 12] of String [9]; asmname '_p_monthname';
  967.        external;
  968.      
  969.      function  GetDayOfWeek (Day, Month, Year : Integer) : Integer;
  970.        asmname '_p_dayofweek';
  971.      procedure UnixTimeToTimeStamp (UnixTime : UnixTimeType; var
  972.        aTimeStamp : TimeStamp); asmname '_p_unix_time_to_time_stamp';
  973.      function  TimeStampToUnixTime (protected var aTimeStamp :
  974.        TimeStamp) : UnixTimeType; asmname '_p_time_stamp_to_unix_time';
  975.      function  GetMicroSecondTime : MicroSecondTimeType;
  976.        asmname '_p_get_micro_second_time';
  977.      
  978.      { Is the year a leap year? }
  979.      function  IsLeapYear (Year : Integer) : Boolean;
  980.        asmname '_p_is_leap_year';
  981.      
  982.      { Returns the length of the month, taking leap years into account. }
  983.      function  MonthLength (Month, Year : Integer) : Integer;
  984.        asmname '_p_month_length';
  985.      
  986.      procedure Sleep (Seconds : Integer); asmname '_p_sleep';
  987.      procedure SleepMicroSeconds (MicroSeconds : Integer);
  988.        asmname '_p_sleep_microseconds';
  989.      function  Alarm (Seconds : Integer) : Integer; asmname '_p_alarm';
  990.      procedure UnixTimeToTime (UnixTime : UnixTimeType; var Year, Month,
  991.        Day, Hour, Minute, Second : Integer);
  992.        asmname '_p_unix_time_to_time';
  993.      function  TimeToUnixTime (Year, Month, Day, Hour, Minute, Second :
  994.        Integer) : UnixTimeType; asmname '_p_time_to_unix_time';
  995.      
  996.      { Get the real time. MicroSecond can be null and is ignored then. }
  997.      function  GetUnixTime (var MicroSecond : Integer) : UnixTimeType;
  998.        asmname '_p_get_unix_time';
  999.      
  1000.      { Get the CPU time used. MicroSecond can be null and is ignored
  1001.        then.
  1002.        Now, GetCPUTime can measure long CPU times reliably on most
  1003.        systems
  1004.        (e.g. Solaris where it didn't work before). }
  1005.      function  GetCPUTime (var MicroSecond : Integer) : Integer;
  1006.        asmname '_p_get_cpu_time';
  1007.      
  1008.      {
  1009.        Formats a TimeStamp value according to a Format string. The format
  1010.        string can contain date/time items consisting of `%', followed by
  1011.        the specifiers listed below. All characters outside of these items
  1012.        are copied to the result unmodified. The specifiers correspond to
  1013.        those of the C function strftime(), including POSIX.2 and glibc
  1014.        extensions and some more extensions. The extensions are also
  1015.        available on systems whose strftime() doesn't support them.
  1016.      
  1017.        The following modifiers may appear after the `%':
  1018.      
  1019.        `_'  The item is left padded with spaces to the given or default
  1020.             width.
  1021.      
  1022.        `-'  The item is not padded at all.
  1023.      
  1024.        `0'  The item is left padded with zeros to the given or default
  1025.             width.
  1026.      
  1027.        `/'  The item is right trimmed if it is longer than the given
  1028.             width.
  1029.      
  1030.        `^'  The item is converted to upper case.
  1031.      
  1032.        `~'  The item is converted to lower case.
  1033.      
  1034.        After zero or more of these flags, an optional width may be
  1035.        specified for padding and trimming. It must be given as a decimal
  1036.        number (not starting with `0' since `0' has a meaning of its own,
  1037.        see above).
  1038.      
  1039.        Afterwards, the following optional modifiers may follow. Their
  1040.        meaning is locale-dependent, and many systems and locales just
  1041.        ignore them.
  1042.      
  1043.        `E'  Use the locale's alternate representation for date and time.
  1044.             In a Japanese locale, for example, `%Ex' might yield a date
  1045.             format based on the Japanese Emperors' reigns.
  1046.      
  1047.        `O'  Use the locale's alternate numeric symbols for numbers. This
  1048.             modifier applies only to numeric format specifiers.
  1049.      
  1050.        Finally, exactly one of the following specifiers must appear. The
  1051.        padding rules listed here are the defaults that can be overriden
  1052.        with the modifiers listed above.
  1053.      
  1054.        `a'  The abbreviated weekday name according to the current locale.
  1055.      
  1056.        `A'  The full weekday name according to the current locale.
  1057.      
  1058.        `b'  The abbreviated month name according to the current locale.
  1059.      
  1060.        `B'  The full month name according to the current locale.
  1061.      
  1062.        `c'  The preferred date and time representation for the current
  1063.             locale.
  1064.      
  1065.        `C'  The century of the year. This is equivalent to the greatest
  1066.             integer not greater than the year divided by 100.
  1067.      
  1068.        `d'  The day of the month as a decimal number (`01' .. `31').
  1069.      
  1070.        `D'  The date using the format `%m/%d/%y'. NOTE: Don't use this
  1071.             format if it can be avoided. Things like this caused Y2K
  1072.             bugs!
  1073.      
  1074.        `e'  The day of the month like with `%d', but padded with blanks
  1075.             (` 1' .. `31').
  1076.      
  1077.        `F'  The date using the format `%Y-%m-%d'. This is the form
  1078.             specified in the ISO 8601 standard and is the preferred form
  1079.             for all uses.
  1080.      
  1081.        `g'  The year corresponding to the ISO week number, but without
  1082.             the century (`00' .. `99'). This has the same format and
  1083.             value as `y', except that if the ISO week number (see `V')
  1084.             belongs to the previous or next year, that year is used
  1085.             instead. NOTE: Don't use this format if it can be avoided.
  1086.             Things like this caused Y2K bugs!
  1087.      
  1088.        `G'  The year corresponding to the ISO week number. This has the
  1089.             same format and value as `Y', except that if the ISO week
  1090.             number (see `V') belongs to the previous or next year, that
  1091.             year is used instead.
  1092.      
  1093.        `h'  The abbreviated month name according to the current locale.
  1094.             This is the same as `b'.
  1095.      
  1096.        `H'  The hour as a decimal number, using a 24-hour clock
  1097.             (`00' .. `23').
  1098.      
  1099.        `I'  The hour as a decimal number, using a 12-hour clock
  1100.             (`01' .. `12').
  1101.      
  1102.        `j'  The day of the year as a decimal number (`001' .. `366').
  1103.      
  1104.        `k'  The hour as a decimal number, using a 24-hour clock like `H',
  1105.             but padded with blanks (` 0' .. `23').
  1106.      
  1107.        `l'  The hour as a decimal number, using a 12-hour clock like `I',
  1108.             but padded with blanks (` 1' .. `12').
  1109.      
  1110.        `m'  The month as a decimal number (`01' .. `12').
  1111.      
  1112.        `M'  The minute as a decimal number (`00' .. `59').
  1113.      
  1114.        `n'  A single newline character.
  1115.      
  1116.        `p'  Either `AM' or `PM', according to the given time value; or
  1117.             the corresponding strings for the current locale. Noon is
  1118.             treated as `PM' and midnight as `AM'.
  1119.      
  1120.        `P'  Either `am' or `pm', according to the given time value; or
  1121.             the corresponding strings for the current locale, printed in
  1122.             lowercase characters. Noon is treated as `pm' and midnight as
  1123.             `am'.
  1124.      
  1125.        `Q'  The fractional part of the second. This format has special
  1126.             effects on the modifiers. The width, if given, determines the
  1127.             number of digits to output. Therefore, no actual clipping or
  1128.             trimming is done. However, if padding with spaces is
  1129.             specified, any trailing (i.e., left!) zeros are converted to
  1130.             spaces, and if "no padding" is specified, they are removed.
  1131.             The default is "padding with zeros", i.e. trailing zeros are
  1132.             left unchanged. The digits are cut when necessary without
  1133.             rounding (otherwise, the value would not be consistent with
  1134.             the seconds given by `S' and `s'). Note that GPC's TimeStamp
  1135.             currently provides for microsecond resolution, so there are
  1136.             at most 6 valid digits (which is also the default width), any
  1137.             further digits will be 0 (but if TimeStamp will ever change,
  1138.             this format will be adjusted). However, the actual resolution
  1139.             provided by the operating system via GetTimeStamp etc. may be
  1140.             far lower (e.g., ~1/18s under Dos).
  1141.      
  1142.        `r'  The complete time using the AM/PM format of the current
  1143.             locale.
  1144.      
  1145.        `R'  The hour and minute in decimal numbers using the format
  1146.             `%H:%M'.
  1147.      
  1148.        `s'  Unix time, i.e. the number of seconds since the epoch, i.e.,
  1149.             since 1970-01-01 00:00:00 UTC. Leap seconds are not counted
  1150.             unless leap second support is available.
  1151.      
  1152.        `S'  The seconds as a decimal number (`00' .. `60').
  1153.      
  1154.        `t'  A single tab character.
  1155.      
  1156.        `T'  The time using decimal numbers using the format `%H:%M:%S'.
  1157.      
  1158.        `u'  The day of the week as a decimal number (`1' .. `7'), Monday
  1159.             being `1'.
  1160.      
  1161.        `U'  The week number of the current year as a decimal number
  1162.             (`00' .. `53'), starting with the first Sunday as the first
  1163.             day of the first week. Days preceding the first Sunday in the
  1164.             year are considered to be in week `00'.
  1165.      
  1166.        `V'  The ISO 8601:1988 week number as a decimal number
  1167.             (`01' .. `53'). ISO weeks start with Monday and end with
  1168.             Sunday. Week `01' of a year is the first week which has the
  1169.             majority of its days in that year; this is equivalent to the
  1170.             week containing the year's first Thursday, and it is also
  1171.             equivalent to the week containing January 4. Week `01' of a
  1172.             year can contain days from the previous year. The week before
  1173.             week `01' of a year is the last week (`52' or `53') of the
  1174.             previous year even if it contains days from the new year.
  1175.      
  1176.        `w'  The day of the week as a decimal number (`0' .. `6'), Sunday
  1177.             being `0'.
  1178.      
  1179.        `W'  The week number of the current year as a decimal number
  1180.             (`00' .. `53'), starting with the first Monday as the first
  1181.             day of the first week. All days preceding the first Monday in
  1182.             the year are considered to be in week `00'.
  1183.      
  1184.        `x'  The preferred date representation for the current locale, but
  1185.             without the time.
  1186.      
  1187.        `X'  The preferred time representation for the current locale, but
  1188.             with no date.
  1189.      
  1190.        `y'  The year without a century as a decimal number
  1191.             (`00' .. `99'). This is equivalent to the year modulo 100.
  1192.             NOTE: Don't use this format if it can be avoided. Things like
  1193.             this caused Y2K bugs!
  1194.      
  1195.        `Y'  The year as a decimal number, using the Gregorian calendar.
  1196.             Years before the year `1' are numbered `0', `-1', and so on.
  1197.      
  1198.        `z'  RFC 822/ISO 8601:1988 style numeric time zone (e.g., `-0600'
  1199.             or `+0100'), or nothing if no time zone is determinable.
  1200.      
  1201.        `Z'  The time zone abbreviation (empty if the time zone can't be
  1202.             determined).
  1203.      
  1204.        `%'  (i.e., an item `%%') A literal `%' character.
  1205.      }
  1206.      function  FormatTime (const Time : TimeStamp; const Format :
  1207.        String) : TString; asmname '_p_format_time';
  1208.      
  1209.      { ==================== FILE HANDLING ROUTINES ==================== }
  1210.      
  1211.      { File handling routines and their support, mostly from files.pas
  1212.        and file.c }
  1213.      
  1214.      type
  1215.        FileSizeType = LongInt;
  1216.      
  1217.      procedure GetBinding   (protected var aFile : AnyFile; var
  1218.        aBinding : BindingType); asmname '_p_binding';
  1219.      procedure ClearBinding (var aBinding : BindingType);
  1220.        asmname '_p_clearbinding';
  1221.      
  1222.      { TFDD interface @@ Subject to change! Use with caution! }
  1223.      
  1224.      type
  1225.        TOpenMode   = (foNone, foReset, foRewrite, foAppend, foSeekRead,
  1226.        foSeekWrite, foSeekUpdate);
  1227.        TOpenProc   = procedure (var PrivateData; Mode : TOpenMode);
  1228.        TSelectFunc = function  (var PrivateData; Writing : Boolean) :
  1229.        Integer; { called before select(), must return a handle }
  1230.        TSelectProc = procedure (var PrivateData; var ReadSelect,
  1231.        WriteSelect, ExceptSelect : Boolean); { called before and after
  1232.        select() }
  1233.        TReadFunc   = function  (var PrivateData; var   Buffer; Size :
  1234.        SizeType) : SizeType;
  1235.        TWriteFunc  = function  (var PrivateData; const Buffer; Size :
  1236.        SizeType) : SizeType;
  1237.        TFileProc   = procedure (var PrivateData);
  1238.        TFlushProc  = TFileProc;
  1239.        TCloseProc  = TFileProc;
  1240.        TDoneProc   = TFileProc;
  1241.      
  1242.      procedure AssignTFDD (var f : AnyFile;
  1243.                            OpenProc    : TOpenProc;
  1244.                            SelectFunc  : TSelectFunc;
  1245.                            SelectProc  : TSelectProc;
  1246.                            ReadFunc    : TReadFunc;
  1247.                            WriteFunc   : TWriteFunc;
  1248.                            FlushProc   : TFlushProc;
  1249.                            CloseProc   : TCloseProc;
  1250.                            DoneProc    : TDoneProc;
  1251.                            PrivateData : Pointer);
  1252.        asmname '_p_assign_tfdd';
  1253.      
  1254.      procedure SetTFDD    (var f : AnyFile;
  1255.                            OpenProc    : TOpenProc;
  1256.                            SelectFunc  : TSelectFunc;
  1257.                            SelectProc  : TSelectProc;
  1258.                            ReadFunc    : TReadFunc;
  1259.                            WriteFunc   : TWriteFunc;
  1260.                            FlushProc   : TFlushProc;
  1261.                            CloseProc   : TCloseProc;
  1262.                            DoneProc    : TDoneProc;
  1263.                            PrivateData : Pointer); asmname '_p_set_tfdd';
  1264.      
  1265.      { Any parameter except f may be null }
  1266.      procedure GetTFDD    (var f : AnyFile;
  1267.                            var OpenProc    : TOpenProc;
  1268.                            var SelectFunc  : TSelectFunc;
  1269.                            var SelectProc  : TSelectProc;
  1270.                            var ReadFunc    : TReadFunc;
  1271.                            var WriteFunc   : TWriteFunc;
  1272.                            var FlushProc   : TFlushProc;
  1273.                            var CloseProc   : TCloseProc;
  1274.                            var DoneProc    : TDoneProc;
  1275.                            var PrivateData : Pointer);
  1276.        asmname '_p_get_tfdd';
  1277.      
  1278.      type
  1279.        Natural = 1 .. MaxInt;
  1280.        IOSelectEvents = (SelectReadOrEOF, SelectRead, SelectEOF,
  1281.        SelectWrite, SelectException, SelectAlways);
  1282.      
  1283.      const
  1284.        IOSelectEventMin = (*Low (IOSelectEvents);*)SelectReadOrEOF;
  1285.        IOSelectEventMax = Pred (SelectAlways);
  1286.      
  1287.      type
  1288.        IOSelectType = record
  1289.          f : PAnyFile;
  1290.          Wanted : set of IOSelectEvents;
  1291.          Occurred : set of IOSelectEventMin .. IOSelectEventMax
  1292.        end;
  1293.      
  1294.      { Waits for one of several events to happen. Returns when one or
  1295.        more of the wanted events for one of the files occur. If they have
  1296.        already occurred before calling the function, it returns
  1297.        immediately. MicroSeconds can specify a timeout. If it is 0, the
  1298.        function will return immediately, whether or not an event has
  1299.        occurred. If it is negative, the function will wait forever until
  1300.        an event occurs. The Events parameter can be null, in which case
  1301.        the function only waits for the timeout. If any of the file
  1302.        pointers (f) in Events are nil or the files pointed to are closed,
  1303.        they are simply ignored for convenience.
  1304.      
  1305.        It returns the index of one of the files for which any event has
  1306.        occurred. If events have occurred for several files, is it
  1307.        undefined which of these file's index is returned. If no event
  1308.        occurs until the timeout, 0 is returned. If an error occurs or the
  1309.        target system does not have a select() system call and Events is
  1310.        not null, a negative value is returned. In the Occurred field of
  1311.        the elements of Events, events that have occurred are set. The
  1312.        state of events not wanted is undefined.
  1313.      
  1314.        The possible events are:
  1315.        SelectReadOrEOF: the file is at EOF or data can be read now.
  1316.        SelectRead:      data can be read now.
  1317.        SelectEOF:       the file is at EOF.
  1318.        SelectWrite:     data can be written now.
  1319.        SelectException: an exception occurred on the file.
  1320.        SelectAlways:    if this is set, *all* requested events will be
  1321.                         checked for this file in any case. Otherwise,
  1322.                         checks may be skipped if already another event
  1323.                         for this or another file was found.
  1324.      
  1325.        Notes:
  1326.        Checking for EOF requires some reading ahead internally (just like
  1327.        the EOF function) which can be avoided by setting SelectReadOrEOF
  1328.        instead of SelectRead and SelectEOF. If this is followed by, e.g.,
  1329.        a BlockRead with 4 parameters, the last parameter will be 0 if and
  1330.        only the file is at EOF, and otherwise, data will be read directly
  1331.        from the file without reading ahead and buffering.
  1332.      
  1333.        SelectAlways should be set for files for which events are
  1334.        considered to be of higher priority than others. Otherwise, if one
  1335.        is interested in just any event, not setting SelectAlways may be a
  1336.        little faster. }
  1337.      function IOSelect (var Events : array [m .. n : Natural] of
  1338.        IOSelectType; MicroSeconds : MicroSecondTimeType) : Integer;
  1339.        asmname '_p_ioselect';
  1340.      
  1341.      { A simpler interface to SelectIO for the most common use. Waits for
  1342.        SelectReadOrEOF on all files and returns an index. }
  1343.      function IOSelectRead (const Files : array [m .. n : Natural] of
  1344.        PAnyFile; MicroSeconds : MicroSecondTimeType) : Integer;
  1345.        asmname '_p_ioselectread';
  1346.      
  1347.      procedure AssignFile   (var T : AnyFile; const Name : String);
  1348.        asmname '_p_assign';
  1349.      procedure AssignBinary (var T : Text; const Name : String);
  1350.        asmname '_p_assign_binary';
  1351.      procedure AssignHandle (var T : AnyFile; Handle : Integer);
  1352.        asmname '_p_assign_handle';
  1353.      
  1354.      { BP compatible seeking routines }
  1355.      function  SeekEOF  (var f : Text) : Boolean; asmname '_p_seekeof';
  1356.      function  SeekEOLn (var f : Text) : Boolean; asmname '_p_seekeoln';
  1357.      
  1358.      { Under development }
  1359.      procedure AnyStringTFDD_Reset (var f : AnyFile; var Buf :
  1360.        ConstAnyString); asmname '_p_anystring_tfdd_reset';
  1361.      (*procedure AnyStringTFDD_Rewrite (var f : AnyFile; var Buf :
  1362.        VarAnyString); asmname '_p_anystring_tfdd_rewrite';*)
  1363.      procedure StringTFDD_Reset (var f : AnyFile; var Buf :
  1364.        ConstAnyString; const s : String); asmname '_p_string_tfdd_reset';
  1365.      (*procedure StringTFDD_Rewrite (var f : AnyFile; var Buf :
  1366.        VarAnyString; var s : String); asmname '_p_string_tfdd_rewrite';*)
  1367.      
  1368.      (*@@iocritical*)procedure FileMove (var f : AnyFile; NewName :
  1369.        CString; Overwrite : Boolean); asmname '_p_mv';
  1370.      
  1371.      { Flags that can be ORed into FileMode. The default value of
  1372.        FileMode is FileMode_Reset_ReadWrite. The somewhat confusing
  1373.        values are meant to be compatible to BP (as far as BP supports
  1374.        them). }
  1375.      const
  1376.        { Allow writing to binary files opened with Reset }
  1377.        FileMode_Reset_ReadWrite      = 2;
  1378.      
  1379.        { Do not allow reading from files opened with Rewrite }
  1380.        FileMode_Rewrite_WriteOnly    = 4;
  1381.      
  1382.        { Do not allow reading from files opened with Extend }
  1383.        FileMode_Extend_WriteOnly     = 8;
  1384.      
  1385.        { Allow writing to text files opened with Reset }
  1386.        FileMode_Text_Reset_ReadWrite = $100;
  1387.      
  1388.      { File mode constants that are ORed for BindingType.Mode and ChMod.
  1389.        The values below are valid for all OSs (as far as supported). If
  1390.        the OS uses different values, they're converted internally. }
  1391.      const
  1392.        fm_SetUID           = 8#4000;
  1393.        fm_SetGID           = 8#2000;
  1394.        fm_Sticky           = 8#1000;
  1395.        fm_UserReadable     = 8#400;
  1396.        fm_UserWritable     = 8#200;
  1397.        fm_UserExecutable   = 8#100;
  1398.        fm_GroupReadable    = 8#40;
  1399.        fm_GroupWritable    = 8#20;
  1400.        fm_GroupExecutable  = 8#10;
  1401.        fm_OthersReadable   = 8#4;
  1402.        fm_OthersWritable   = 8#2;
  1403.        fm_OthersExecutable = 8#1;
  1404.      
  1405.      type
  1406.        TextFile = Text;
  1407.      
  1408.        StatFSBuffer = record
  1409.          BlockSize, BlocksTotal, BlocksFree : LongestInt;
  1410.          FilesTotal, FilesFree : Integer
  1411.        end;
  1412.      
  1413.      procedure CloseFile    (          var aFile : (*@@Any*)File);
  1414.        asmname '_p_close';
  1415.      (*@@IO critical*) procedure ChMod        (          var aFile :
  1416.        AnyFile; Mode : Integer); asmname '_p_chmod';
  1417.      (*@@IO critical*) procedure StatFS       (Path : CString; var Buf :
  1418.        StatFSBuffer); asmname '_p_statfs';
  1419.      
  1420.      { Checks if data are available to be read from aFile. This is
  1421.        similar to
  1422.        `not EOF (aFile)', but does not block on "files" that can grow,
  1423.        like TTYs
  1424.        or pipes. }
  1425.      function  CanRead      (var aFile : AnyFile) : Boolean;
  1426.        asmname '_p_canread';
  1427.      
  1428.      { Get the file handle. }
  1429.      function  FileHandle   (protected var aFile : AnyFile) : Integer;
  1430.        asmname '_p_filehandle';
  1431.      
  1432.      { Lock files }
  1433.      function  FileLock   (var aFile : AnyFile; WriteLock, Block :
  1434.        Boolean) : Boolean; asmname '_p_filelock';
  1435.      function  FileUnlock (var aFile : AnyFile) : Boolean;
  1436.        asmname '_p_fileunlock';
  1437.      
  1438.      const
  1439.        mm_Readable   = 1;
  1440.        mm_Writable   = 2;
  1441.        mm_Executable = 4;
  1442.      
  1443.      function MemoryMap (Start : Pointer; Length : SizeType; Access :
  1444.        Integer; Shared : Boolean;
  1445.                          var aFile : AnyFile; Offset : FileSizeType) :
  1446.        Pointer; asmname '_p_mmap';
  1447.      procedure MemoryUnMap (Start : Pointer; Length : SizeType);
  1448.        asmname '_p_munmap';
  1449.      
  1450.      { File name routines, from filename.pas }
  1451.      
  1452.      {
  1453.        Define constants for different systems:
  1454.      
  1455.        OSDosFlag:         flag to indicate whether the target system is
  1456.                           Dos
  1457.      
  1458.        QuotingCharacter:  the character used to quote wild cards and
  1459.                           other special characters (#0 if not available)
  1460.      
  1461.        PathSeparator:     the separator of multiple paths, e.g. in the
  1462.                           PATH environment variable
  1463.      
  1464.        DirSeparator:      the separator of the directories within a full
  1465.                           file name
  1466.      
  1467.        DirSeparators:     a set of all possible directory and drive name
  1468.                           separators
  1469.      
  1470.        ExtSeparator:      the separator of a file name extension
  1471.      
  1472.        DirRoot:           the name of the root directory
  1473.      
  1474.        DirSelf:           the name of a directory in itself
  1475.      
  1476.        DirParent:         the name of the parent directory
  1477.      
  1478.        MaskNoStdDir:      a file name mask that matches all names except
  1479.                           the standard directories DirSelf and DirParent
  1480.      
  1481.        NullDeviceName:    the full file name of the null device
  1482.      
  1483.        TTYDeviceName:     the full file name of the current TTY
  1484.      
  1485.        ConsoleDeviceName: the full file name of the system console. On
  1486.                           Dos systems, this is the same as the TTY, but
  1487.                           on systems that allow remote login, this is a
  1488.                           different thing and may reach a completely
  1489.                           different user than the one running the
  1490.                           program, so use with care.
  1491.      
  1492.        EnvVarCharsFirst:  the characters accepted at the beginning of the
  1493.                           name of an environment variable without quoting
  1494.      
  1495.        EnvVarChars:       the characters accepted in the name of an
  1496.                           environment variable without quoting
  1497.      
  1498.        PathEnvVar:        the name of the environment variable which
  1499.                           (usually) contains the executable search path
  1500.      
  1501.        ShellEnvVar:       the name of the environment variable which
  1502.                           (usually) contains the path of the shell
  1503.                           executable (see GetShellPath)
  1504.      
  1505.        ShellExecCommand:  the option to the (default) shell to execute
  1506.                           the command specified in the following argument
  1507.                           (see GetShellPath)
  1508.      
  1509.        ConfigFileMask:    a mask for the option file name as returned by
  1510.                           ConfigFileName
  1511.      
  1512.        FileNamesCaseSensitive:
  1513.                           flag to indicate whether file names are case
  1514.                           sensitive
  1515.      }
  1516.      
  1517.      const
  1518.        UnixShellEnvVar        = 'SHELL';
  1519.        UnixShellExecCommand   = '-c';
  1520.      
  1521.      {$ifdef __OS_DOS__}
  1522.      
  1523.      const
  1524.        OSDosFlag              = True;
  1525.        QuotingCharacter       = #0;
  1526.        PathSeparator          = {$ifdef __CYGWIN32__} ':' {$else} ';'
  1527.        {$endif};
  1528.        DirSeparator           = '\';
  1529.        DirSeparators          = [':', '\', '/'];
  1530.        ExtSeparator           = '.';
  1531.        DirRoot                = '\';
  1532.        DirSelf                = '.';
  1533.        DirParent              = '..';
  1534.        MaskNoStdDir           = '{*,.[^.],..?*}';
  1535.        NullDeviceName         = 'nul';
  1536.        TTYDeviceName          = 'con';
  1537.        ConsoleDeviceName      = 'con';
  1538.        EnvVarCharsFirst       = ['A' .. 'Z', 'a' .. 'z', '_'];
  1539.        EnvVarChars            = EnvVarCharsFirst + ['0' .. '9'];
  1540.        PathEnvVar             = 'PATH';
  1541.        ShellEnvVar            = 'COMSPEC';
  1542.        ShellExecCommand       = '/c';
  1543.        ConfigFileMask         = '*.cfg';
  1544.        FileNamesCaseSensitive = False;
  1545.      
  1546.      {$else}
  1547.      
  1548.      const
  1549.        OSDosFlag              = False;
  1550.        QuotingCharacter       = '\';
  1551.        PathSeparator          = ':';
  1552.        DirSeparator           = '/';
  1553.        DirSeparators          = ['/'];
  1554.        ExtSeparator           = '.';
  1555.        DirRoot                = '/';
  1556.        DirSelf                = '.';
  1557.        DirParent              = '..';
  1558.        MaskNoStdDir           = '{*,.[^.],..?*}';
  1559.        NullDeviceName         = '/dev/null';
  1560.        TTYDeviceName          = '/dev/tty';
  1561.        ConsoleDeviceName      = '/dev/console';
  1562.        EnvVarCharsFirst       = ['A' .. 'Z', 'a' .. 'z', '_'];
  1563.        EnvVarChars            = EnvVarCharsFirst + ['0' .. '9'];
  1564.        PathEnvVar             = 'PATH';
  1565.        ShellEnvVar            = UnixShellEnvVar;
  1566.        ShellExecCommand       = UnixShellExecCommand;
  1567.        ConfigFileMask         = '.*';
  1568.        FileNamesCaseSensitive = True;
  1569.      
  1570.      {$endif}
  1571.      
  1572.      const
  1573.        WildCardChars = ['*', '?', '[', ']'];
  1574.        FileNameSpecialChars = (WildCardChars + SpaceCharacters +
  1575.        ['{', '}', '$', QuotingCharacter]) - DirSeparators;
  1576.      
  1577.      type
  1578.        DirPtr = Pointer;
  1579.      
  1580.        { `+ 1' is a waste, but it is so the size of the array is not
  1581.          zero for Count = 0 }
  1582.        PPStrings = ^TPStrings;
  1583.        TPStrings (Count : Cardinal) = array [1 .. Count + 1] of ^String;
  1584.      
  1585.        GlobBuffer = record
  1586.          Result    : PPStrings;
  1587.          Internal1 : Pointer;
  1588.          Internal2 : PCStrings;
  1589.          Internal3 : Integer
  1590.        end;
  1591.      
  1592.      { Convert ch to lower case if FileNamesCaseSensitive is False, leave
  1593.        it unchanged otherwise. }
  1594.      function  FileNameLoCase (ch : Char) : Char;
  1595.        asmname '_p_filenamelocase';
  1596.      
  1597.      { Change a file name to use the OS dependent directory separator }
  1598.      function  Slash2OSDirSeparator (const s : String) : TString;
  1599.        asmname '_p_slash2osdirseparator';
  1600.      
  1601.      { Change a file name to use '/' as directory separator }
  1602.      function  OSDirSeparator2Slash (const s : String) : TString;
  1603.        asmname '_p_osdirseparator2slash';
  1604.      
  1605.      { Like Slash2OSDirSeparator for CStrings -- NOTE: overwrites the
  1606.        CString }
  1607.      function  Slash2OSDirSeparator_CString (s : CString) : CString;
  1608.        asmname '_p_slash2osdirseparator_cstring';
  1609.      
  1610.      { Like OSDirSeparator2Slash for CStrings -- NOTE: overwrites the
  1611.        CString }
  1612.      function  OSDirSeparator2Slash_CString (s : CString) : CString;
  1613.        asmname '_p_osdirseparator2slash_cstring';
  1614.      
  1615.      { Add a DirSeparator to the end of s, if there is not already one
  1616.        and s denotes an existing directory }
  1617.      function  AddDirSeparator (const s : String) : TString;
  1618.        asmname '_p_adddirseparator';
  1619.      
  1620.      { Like AddDirSeparator, but also if the directory does not exist }
  1621.      function  ForceAddDirSeparator (const s : String) : TString;
  1622.        asmname '_p_forceadddirseparator';
  1623.      
  1624.      { Remove all trailing DirSeparators from s, if there are any, as
  1625.        long as removing them doesn't change the meaning (i.e., they don't
  1626.        denote the root directory. }
  1627.      function  RemoveDirSeparator (const s : String) : TString;
  1628.        asmname '_p_removedirseparator';
  1629.      
  1630.      { Returns the current directory using OS dependent directory
  1631.        separators }
  1632.      function  GetCurrentDirectory     : TString;
  1633.        asmname '_p_get_current_directory';
  1634.      
  1635.      { Returns a directory suitable for storing temporary files using OS
  1636.        dependent directory separators. If found, the result always ends
  1637.        in DirSeparator. If no suitable directory is found, an empty
  1638.        string is returned. }
  1639.      function  GetTempDirectory        : TString;
  1640.        asmname '_p_get_temp_directory';
  1641.      
  1642.      { Returns a non-existing file name in the directory given. If the
  1643.        directory doesn't exist or the Directory name is empty, a runtime
  1644.        error is raised, and GetTempFileNameInDirectory returns the empty
  1645.        string. }
  1646.      (*@@iocritical*)function  GetTempFileNameInDirectory (const
  1647.        Directory : String) : TString;
  1648.        asmname '_p_get_temp_file_name_in_directory';
  1649.      
  1650.      { Returns a non-existing file name in GetTempDirectory. If no temp
  1651.        directory is found, i.e. GetTempDirectory returns the empty
  1652.        string, a runtime error is raised, and GetTempFileName returns the
  1653.        empty string as well. }
  1654.      (*@@iocritical*)function  GetTempFileName         : TString;
  1655.        asmname '_p_get_temp_file_name';
  1656.      
  1657.      { The same as GetTempFileName, but returns a CString allocated from
  1658.        the heap. }
  1659.      (*@@iocritical*)function  GetTempFileName_CString : CString;
  1660.        asmname '_p_get_temp_file_name_cstring';
  1661.      
  1662.      { Get the external name of a file }
  1663.      function  FileName (protected var f : AnyFile) : TString;
  1664.        asmname '_p_file_name';
  1665.      
  1666.      { Returns true if the given file name is an existing plain file }
  1667.      function  FileExists      (const aFileName : String) : Boolean;
  1668.        asmname '_p_file_exists';
  1669.      
  1670.      { Returns True if the given file name is an existing directory }
  1671.      function  DirectoryExists (const aFileName : String) : Boolean;
  1672.        asmname '_p_directory_exists';
  1673.      
  1674.      { Returns True if the given file name is an existing file, directory
  1675.        or special file (device, pipe, socket, etc.) }
  1676.      function  PathExists      (const aFileName : String) : Boolean;
  1677.        asmname '_p_path_exists';
  1678.      
  1679.      { If a file of the given name exists in one of the directories given
  1680.        in DirList (separated by PathSeparator), returns the full path,
  1681.        otherwise returns an empty string. If aFileName already contains
  1682.        an element of DirSeparators, returns Slash2OSDirSeparator
  1683.        (aFileName) if it exists. }
  1684.      function  FSearch (const aFileName, DirList : String) : TString;
  1685.        asmname '_p_fsearch';
  1686.      
  1687.      { Like FSearch, but only find executable files. Under Dos, if not
  1688.        found, the function tries appending '.com', '.exe', '.bat' and
  1689.        `.cmd' (the last one only if $COMSPEC points to a `cmd.exe'), so
  1690.        you don't have to specify these extensions in aFileName (and with
  1691.        respect to portability, it might be preferable not to do so). }
  1692.      function  FSearchExecutable (const aFileName, DirList : String) :
  1693.        TString; asmname '_p_fsearch_executable';
  1694.      
  1695.      { Replaces all occurrences of `$FOO' and `~' in s by the value of
  1696.        the environment variables FOO or HOME, respectively. If a variable
  1697.        is not defined, the function returns False, and s contains the
  1698.        name of the undefined variable (or the empty string if the
  1699.        variable name is invalid, i.e., doesn't start with a character
  1700.        from EnvVarCharsFirst). Otherwise, if all variables are found, s
  1701.        contains the replaced string, and True is returned. }
  1702.      function  ExpandEnvironment (var s : String) : Boolean;
  1703.        asmname '_p_expand_environment';
  1704.      
  1705.      { Expands the given path name to a full path name. Relative paths
  1706.        are expanded using the current directory, and occurrences of
  1707.        DirSelf and DirParent are resolved. Under Dos, the result is
  1708.        converted to lower case and a trailing ExtSeparator (except in a
  1709.        trailing DirSelf or DirParent) is removed, like Dos does. If the
  1710.        directory, i.e. the path without the file name, is invalid, the
  1711.        empty string is returned. }
  1712.      function  FExpand       (const Path : String) : TString;
  1713.        asmname '_p_fexpand';
  1714.      
  1715.      { Like FExpand, but unquotes the directory before expanding it, and
  1716.        quotes WildCardChars again afterwards. Does not check if the
  1717.        directory is valid (because it may contain wild card characters).
  1718.        Symlinks are expanded only in the directory part, not the file
  1719.        name. }
  1720.      function  FExpandQuoted (const Path : String) : TString;
  1721.        asmname '_p_fexpandquoted';
  1722.      
  1723.      { FExpands Path, and then removes the current directory from it, if
  1724.        it is a prefix of it. If OnlyCurDir is set, the current directory
  1725.        will be removed only if Path denotes a file in, not below, it. }
  1726.      function  RelativePath (const Path : String; OnlyCurDir, Quoted :
  1727.        Boolean) : TString; asmname '_p_relative_path';
  1728.      
  1729.      { Is aFileName a UNC filename? (Always returns False on non-Dos
  1730.        systems.) }
  1731.      function  IsUNC (const aFileName : String) : Boolean;
  1732.        asmname '_p_IsUNC';
  1733.      
  1734.      { Splits a file name into directory, name and extension. Each of
  1735.        Dir, Name and Ext may be null. }
  1736.      procedure FSplit (const Path : String; var Dir, Name, Ext : String);
  1737.        asmname '_p_fsplit';
  1738.      
  1739.      { Functions that extract one or two of the parts from FSplit.
  1740.        DirFromPath returns DirSelf + DirSeparator if the path contains no
  1741.        directory. }
  1742.      function  DirFromPath     (const Path : String) : TString;
  1743.        asmname '_p_dir_from_path';
  1744.      function  NameFromPath    (const Path : String) : TString;
  1745.        asmname '_p_name_from_path';
  1746.      function  ExtFromPath     (const Path : String) : TString;
  1747.        asmname '_p_ext_from_path';
  1748.      function  NameExtFromPath (const Path : String) : TString;
  1749.        asmname '_p_name_ext_from_path';
  1750.      
  1751.      { Start reading a directory. If successful, a pointer is returned
  1752.        that can be used for subsequent calls to ReadDir and finally
  1753.        CloseDir. On failure, an I/O error is raised and (in case it is
  1754.        ignored) nil is returned. }
  1755.      (*@@iocritical*)function  OpenDir  (const Name : String) : DirPtr;
  1756.        asmname '_p_opendir';
  1757.      
  1758.      { Reads one entry from the directory Dir, and returns the file name.
  1759.        On errors or end of directory, the empty string is returned. }
  1760.      function  ReadDir  (Dir : DirPtr) : TString; asmname '_p_readdir';
  1761.      
  1762.      { Closes a directory opened with OpenDir. }
  1763.      (*@@iocritical*)procedure CloseDir (Dir : DirPtr);
  1764.        asmname '_p_closedir';
  1765.      
  1766.      { Returns the first position of a non-quoted character of CharSet in
  1767.        s, or 0 if no such character exists. }
  1768.      function  FindNonQuotedChar (Chars : CharSet; const s : String;
  1769.        From : Integer) : Integer; asmname '_p_findnonquotedchar';
  1770.      
  1771.      { Returns the first occurence of SubString in s that is not quoted
  1772.        at the beginning, or 0 if no such occurence exists. }
  1773.      function  FindNonQuotedStr (const SubString, s : String; From :
  1774.        Integer) : Integer; asmname '_p_findnonquotedstr';
  1775.      
  1776.      { Does a string contain non-quoted wildcard characters? }
  1777.      function  HasWildCards (const s : String) : Boolean;
  1778.        asmname '_p_haswildcards';
  1779.      
  1780.      { Does a string contain non-quoted wildcard characters, braces or
  1781.        spaces? }
  1782.      function  HasWildCardsOrBraces (const s : String) : Boolean;
  1783.        asmname '_p_haswildcardsorbraces';
  1784.      
  1785.      { Insert QuotingCharacter into s before any special characters }
  1786.      function  QuoteFileName (const s : String; const SpecialCharacters :
  1787.        CharSet) : TString; asmname '_p_quote_filename';
  1788.      
  1789.      { Remove QuotingCharacter from s }
  1790.      function  UnQuoteFileName (const s : String) : TString;
  1791.        asmname '_p_unquote_filename';
  1792.      
  1793.      { Splits s at non-quoted spaces and expands non-quoted braces like
  1794.        bash does. The result and its entries should be disposed after
  1795.        usage, e.g. with DisposePPStrings. }
  1796.      function  BraceExpand (const s : String) : PPStrings;
  1797.        asmname '_p_braceexpand';
  1798.      
  1799.      { Dispose of a PPStrings array as well as the strings it contains.
  1800.        If you want to keep the strings (by assigning them to other string
  1801.        pointers), you should instead free the PPStrings array with
  1802.        `Dispose'. }
  1803.      procedure DisposePPStrings (Strings : PPStrings);
  1804.        asmname '_p_DisposePPStrings';
  1805.      
  1806.      { Tests if a file name matches a shell wildcard pattern (?, *, []) }
  1807.      function  FileNameMatch (const Pattern, Name : String) : Boolean;
  1808.        asmname '_p_filenamematch';
  1809.      
  1810.      { FileNameMatch with BraceExpand }
  1811.      function  MultiFileNameMatch (const Pattern, Name : String) :
  1812.        Boolean; asmname '_p_multifilenamematch';
  1813.      
  1814.      { File name globbing }
  1815.      { GlobInit is implied by Glob and MultiGlob, not by GlobOn and
  1816.        MultiGlobOn. GlobOn and MultiGlobOn must be called after GlobInit,
  1817.        Glob or MultiGlob. MultiGlob and MultiGlobOn do brace expansion,
  1818.        Glob and GlobOn do not. GlobFree frees the memory allocated by the
  1819.        globbing functions and invalidates the results in Buf. It should
  1820.        be called after globbing. }
  1821.      procedure GlobInit    (var Buf : GlobBuffer); asmname '_p_globinit';
  1822.      procedure Glob        (var Buf : GlobBuffer; const Pattern :
  1823.        String); asmname '_p_glob';
  1824.      procedure GlobOn      (var Buf : GlobBuffer; const Pattern :
  1825.        String); asmname '_p_globon';
  1826.      procedure MultiGlob   (var Buf : GlobBuffer; const Pattern :
  1827.        String); asmname '_p_multiglob';
  1828.      procedure MultiGlobOn (var Buf : GlobBuffer; const Pattern :
  1829.        String); asmname '_p_multiglobon';
  1830.      procedure GlobFree    (var Buf : GlobBuffer); asmname '_p_globfree';
  1831.      
  1832.      type
  1833.        TPasswordEntry = record
  1834.          UserName, RealName, Password, HomeDirectory, Shell : TString;
  1835.          UID, GID : Integer
  1836.        end;
  1837.      
  1838.        PPasswordEntries = ^TPasswordEntries;
  1839.        TPasswordEntries (Count : Integer) = array [1 .. Count] of
  1840.        TPasswordEntry;
  1841.      
  1842.      { Finds a password entry by user name. Returns True if found, False
  1843.        otherwise. }
  1844.      function  GetPasswordEntryByName (const UserName : String; var
  1845.        Entry : TPasswordEntry) : Boolean;
  1846.        asmname '_p_getpasswordentrybyname';
  1847.      
  1848.      { Finds a password entry by UID. Returns True if found, False
  1849.        otherwise. }
  1850.      function  GetPasswordEntryByUID  (UID : Integer; var Entry :
  1851.        TPasswordEntry) : Boolean; asmname '_p_getpasswordentrybyuid';
  1852.      
  1853.      { Returns all password entries, or nil if none found. }
  1854.      function  GetPasswordEntries : PPasswordEntries;
  1855.        asmname '_p_getpasswordentries';
  1856.      
  1857.      { Returns the mount point (Unix) or drive (Dos) which is part of the
  1858.        given path. If the path does not contain any (i.e., is a relative
  1859.        path), an empty string is returned. Therefore, if you want to get
  1860.        the mount point or drive in any case, apply `FExpand' or
  1861.        `RealPath' to the argument. }
  1862.      function  GetMountPoint (const Path : String) = Result : TString;
  1863.        asmname '_p_GetMountPoint';
  1864.      
  1865.      type
  1866.        TSystemInfo = record
  1867.          OSName,
  1868.          OSRelease,
  1869.          OSVersion,
  1870.          MachineType,
  1871.          HostName,
  1872.          DomainName : TString
  1873.        end;
  1874.      
  1875.      { Returns system information if available. Fields not available will
  1876.        be empty. }
  1877.      function  SystemInfo : TSystemInfo; asmname '_p_SystemInfo';
  1878.      
  1879.      { Returns the path to the shell (as the return value) and the option
  1880.        that makes it execute the command specified in the following
  1881.        argument (in `Option'). Usually these are the environment value of
  1882.        ShellEnvVar, and ShellExecCommand, but on Dos systems, the
  1883.        function will first try UnixShellEnvVar, and UnixShellExecCommand
  1884.        because ShellEnvVar will usually point to command.com, but
  1885.        UnixShellEnvVar can point to bash which is usually a better choice
  1886.        when present. If UnixShellEnvVar is not set, or the shell given
  1887.        does not exist, it will use ShellEnvVar, and ShellExecCommand.
  1888.        Option may be null (in case you want to invoke the shell
  1889.        interactively). }
  1890.      function  GetShellPath (var Option : String) : TString;
  1891.        asmname '_p_GetShellPath';
  1892.      
  1893.      { Returns the path of the running executable. NOTE: On most systems,
  1894.        this is *not* guaranteed to be the full path, but often just the
  1895.        same as `ParamStr (0)' which usually is the name given on the
  1896.        command line. Only on some systems with special support, it
  1897.        returns the full path when `ParamStr (0)' doesn't. }
  1898.      function  ExecutablePath : TString; asmname '_p_executable_path';
  1899.      
  1900.      { Returns a file name suitable for a global (system-wide) or local
  1901.        (user-specific) configuration file, depending on the Global
  1902.        parameter. The function does not guarantee that the file name
  1903.        returned exists or is readable or writable.
  1904.      
  1905.        In the following table, the base name `<base>' is given with the
  1906.        Name parameter. If it is empty, the base name is the name of the
  1907.        running program (as returned by ExecutablePath, without directory
  1908.        and extension. `<prefix>' (Unix only) stands for the value of the
  1909.        Prefix parameter (usual values include '', '/usr' and
  1910.        '/usr/local'). `<dir>' (Dos only) stands for the directory where
  1911.        the running program resides. `$foo' stands for the value of the
  1912.        environment variable `foo'.
  1913.      
  1914.               Global                    Local
  1915.        Unix:  <prefix>/etc/<base>.conf  $HOME/.<base>
  1916.      
  1917.        Dos:   $DJDIR\etc\<base>.ini     $HOME\<base>.cfg
  1918.               <dir>\<base>.ini          <dir>\<base>.cfg
  1919.      
  1920.        As you see, there are two possibilities under Dos. If the first
  1921.        file exists, it is returned. Otherwise, if the second file exists,
  1922.        that is returned. If none of them exists (but the program might
  1923.        want to create a file), if the environment variable (DJDIR or
  1924.        HOME, respectively) is set, the first file name is returned,
  1925.        otherwise the second one. This rather complicated scheme should
  1926.        give the most reasonable results for systems with or without DJGPP
  1927.        installed, and with or without already existing config files. Note
  1928.        that DJDIR is always set on systems with DJGPP installed, while
  1929.        HOME is not. However, it is easy for users to set it if they want
  1930.        their config files in a certain directory rather than with the
  1931.        executables. }
  1932.      function  ConfigFileName (const Prefix, Name : String; Global :
  1933.        Boolean) : TString; asmname '_p_config_file_name';
  1934.      
  1935.      { Returns a directory name suitable for global, machine-independent
  1936.        data. The function garantees that the name returned ends with a
  1937.        DirSeparator, but does not guarantee that it exists or is
  1938.        readable or writable.
  1939.      
  1940.        Note: If the prefix is empty, it is assumed to be '/usr'. (If you
  1941.        really want /share, you could pass '/' as the prefix, but that's
  1942.        very uncommon.)
  1943.      
  1944.        Unix: <prefix>/share/<base>/
  1945.      
  1946.        Dos:  $DJDIR\share\<base>\
  1947.              <dir>\
  1948.      
  1949.        About the symbols used above, and the two possibilities under Dos,
  1950.        see the comments for ConfigFileName. }
  1951.      function  DataDirectoryName (const Prefix, Name : String) : TString;
  1952.        asmname '_p_data_directory_name';
  1953.      
  1954.      { ==================== MATHEMATICAL ROUTINES ===================== }
  1955.      
  1956.      function  IsInfinity   (x : Extended) : Boolean; attribute (const);
  1957.        asmname '_p_isinf';
  1958.      function  IsNotANumber (x : Extended) : Boolean; attribute (const);
  1959.        asmname '_p_isnan';
  1960.      procedure SplitReal    (x : Extended; var Exponent : Integer; var
  1961.        Mantissa : Extended); asmname '_p_frexp';
  1962.      function  SinH         (x : Double)    : Double; asmname '_p_sinh';
  1963.      function  CosH         (x : Double)    : Double; asmname '_p_cosh';
  1964.      function  Arctan2      (y, x : Double) : Double;
  1965.        asmname '_p_arctan2';
  1966.      
  1967.      type
  1968.        RandomSeedType = Cardinal (32);
  1969.        RandomizeType  = ^procedure;
  1970.        SeedRandomType = ^procedure (Seed : RandomSeedType);
  1971.        RandRealType   = ^function : LongestReal;
  1972.        RandIntType    = ^function (MaxValue : LongestCard) : LongestCard;
  1973.      
  1974.      var
  1975.        RandomizePtr  : RandomizeType; asmname '_p_randomize_ptr';
  1976.        external;
  1977.        SeedRandomPtr : SeedRandomType; asmname '_p_seedrandom_ptr';
  1978.        external;
  1979.        RandRealPtr   : RandRealType; asmname '_p_randreal_ptr'; external;
  1980.        RandIntPtr    : RandIntType; asmname '_p_randint_ptr'; external;
  1981.      
  1982.      procedure SeedRandom (Seed : RandomSeedType);
  1983.        asmname '_p_seedrandom';
  1984.      
  1985.      end.
  1986.  
  1987.